package com.example.javamaday.leetcode;

public class LeetCodeTest0461 {

    public static void main(String[] args) {
        long cur = System.currentTimeMillis();
        System.out.println(new LeetCodeTest0461().hammingDistance(1577962638 ,1727613287));
        System.out.println(System.currentTimeMillis() - cur);
    }

    public int hammingDistance(int x, int y) {
        int dis = 0;
        long common = 2;
        while (common * 2 <= x || common * 2 <= y) {
            common *= 2;
        }
        while (x >= 0 && y >= 0 && common >= 1) {
            if (x >= common && y >= common) {
                x -= common;
                y -= common;
                common /= 2;
            } else if (x >= common && y < common) {
                x -= common;
                common /= 2;
                dis++;
            } else if (x < common && y >= common) {
                y -= common;
                common /= 2;
                dis++;
            } else {
                common /= 2;
            }
        }
        return dis;
    }

}
